<?php

require_once 'model/dao/GameRepository.php';
require_once 'model/dao/PlayerRepository.php';

require_once 'model/entities/Game.php';
require_once 'model/entities/Player.php';
require_once 'model/entities/Board.php';
require_once 'model/entities/TurnUpdate.php';

require_once "doctrine-orm/Doctrine/ORM/Tools/Setup.php";
use Doctrine\ORM\Configuration,
    Doctrine\ORM\EntityManager,
    Doctrine\ORM\Tools\Setup;

class EntityManagerFactory {
    private static $em;
    private static function init() {
        $lib = "doctrine-orm";
        Setup::registerAutoloadDirectory($lib);

        $paths = array(__DIR__."/entities");        
        $isDevMode = true;

        $connectionOptions = array(
            'driver'   => 'pdo_mysql',
            'path'     => 'localhost',
            'dbname'   => 'mancala',
            'user'     => 'mancala',
            'password' => 'mancala'
        );
        $config = Setup::createAnnotationMetadataConfiguration($paths, $isDevMode);        
        
        $em = EntityManager::create($connectionOptions, $config);
        return $em;
    }
    
    /**
     *
     * @return type EntityManager
     */
    public static function getEntityManager() {
        if ( self::$em == null ) {
            return self::init();
        }
        return self::$em;
    }    
}


 

?>
